//
// Created by Administrator on 2024/3/26.
//
#include<bits/stdc++.h>

using namespace std;
using ll = long long;
#define endl '\n'
int a[20], book[20], n = 4;

void dfs(int k) {
    if (k >= n) {
        for (int i = 0; i < n; i++) {
            cout << a[i];
        }
        cout << endl;
        return;
    }
    for (int i = 0; i < n; i++) {
        if (book[i] == 1)continue;//查表
        a[k] = i + 1;
        book[i] = 1;//写入标记数组
        dfs(k + 1);
        book[i] = 0;//当我们访问完叶子结点后，必须要重置book[i]为未选择状态
    }


}


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin >> n;
    dfs(0);

    return 0;
}